package algorithm.tree;

import algorithm.model.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * leetcode: https://leetcode.com/problems/binary-tree-inorder-traversal/
 * Difficulty:  Medium
 *
 * 树的中序遍历
 * 思路：DFS 深度优先遍历
 * Created by yzy on 2021-02-07 14:47
 */
public class BinaryTreeInorderTraversal {

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        if(root == null) return res;
        inorderDFS(root, res);
        return res;
    }

    private void inorderDFS(TreeNode node, List<Integer> res){
        if(node==null) return;
        inorderDFS(node.left, res);
        res.add(node.val);
        inorderDFS(node.right, res);
    }

}
